﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Windows.Forms;

namespace StudentApartMentManage
{
    public partial class StuMainForm : Form
    {
        string uname;
        public StuMainForm(string uname)
        {
            InitializeComponent();
            this.uname = uname;
        }
        string GetRstr(string sql)
        {
            string str = null;
            string connectionString = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            SqlDataReader r = cmd.ExecuteReader();
            if (r.Read())
            {
                str = r.GetString(0);
            }
            r.Close();
            con.Close();
            return str;
        }

        private void StuMainForm_Load(object sender, EventArgs e)
        {
            string sql = string.Format("select 姓名 from 学生信息表 where 学号='{0}'", uname);
            toolStripStatusLabel1.Text += GetRstr(sql);

        }

        private void 关于系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutSystem absy = new AboutSystem();
            absy.MdiParent = this;
            absy.Show();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确定要退出吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                System.Environment.Exit(System.Environment.ExitCode);
                this.Dispose();
                this.Close();
            }
        }

        private void 电费查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ElectricityInquiry eci = new ElectricityInquiry();
            eci.MdiParent = this;
            eci.Show();
        }

        private void 报修查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DMS dms = new DMS();
            dms.MdiParent = this;
            dms.Show();
        }

        private void 个人资料管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PersonalData pd = new PersonalData(uname);
            pd.MdiParent = this;
            pd.Show();
        }
    }
}
